import routeConfig from './routeConfig-cs'
import counter from './models/counter'
import { createBrowserHistory } from 'history'
import dva from './dva'

const logger = store => next => action => {
    console.log('中间件', action.type);
    return next(action)
}

const app = dva({
    history: createBrowserHistory(),
    initialState: { counter: 12345 },
    onError(err, dispatch) {
        console.log('err', err);
    },
    // 传递中间件
    onAction: [logger],  //logger or [logger] 
    // 监听状态变化
    onStateChange(state) {
        console.log('newState', state);
    },
    onReducer(reducer) {
        return function (state, action) {
            console.log('reducer 即将执行');
            return reducer(state, action)
        }
    },
    onEffect(effect, sagaEffects, model, actionType) {
        return function* (action) {
            console.log('副作用即将产生');
            yield effect(action)
        }
    },
    // 额外的reducer
    extraReducers: {
        abc(state = 123, action) {
            return state
        },
    },

    extraEnhancers: [
        function (createStore) {
            return function (...args) {
                console.log('即将创建仓库1');
                return createStore(...args)
            }
        }, function (createStore) {
            return function (...args) {
                console.log('即将创建仓库2');
                return createStore(...args)
            }
        }
    ]
})

app.model(counter)

app.router(routeConfig)

app.start('#root')